package com.itboye.mengwu.main;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;

import com.itboye.core.object.BaseActivity;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.ui.main.WelcomeActivity;
import com.itboye.mengwu.data.model.HomePageModel;
import com.itboye.mengwu.data.presenter.LunBoPresenter;

public class SplashActivity extends BaseActivity {
	boolean isFirstIn = false;
	public static boolean isScanDone = true;
	static final int GO_HOME = 1500;
	static final int GO_GUIDE = 1501;
	private static final long SPLASH_DELAY_MILLIS_LONG = 1600;
	private static final long SPLASH_DELAY_MILLIS_SHOUT = 1500;
	private static final String SHAREDPREFERENCES_NAME = "firstLogin";

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_splash;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		SharedPreferences preferences = getSharedPreferences(
				SHAREDPREFERENCES_NAME, MODE_PRIVATE);
		isFirstIn = preferences.getBoolean("firstLogin", true);
		if (!isFirstIn) {
			// 使用Handler的postDelayed方法，1.5秒后执行跳转到MainActivity
			mHandler.sendEmptyMessageDelayed(GO_HOME, SPLASH_DELAY_MILLIS_SHOUT);
		} else {
			mHandler.sendEmptyMessageDelayed(GO_GUIDE, SPLASH_DELAY_MILLIS_LONG);
		}

	}

	private void goHome() {
		Intent intent = new Intent(SplashActivity.this, MainActivity.class);
		SplashActivity.this.startActivity(intent);
		SplashActivity.this.finish();
	}

	private void goGuide() {
		Intent intent = new Intent(SplashActivity.this, WelcomeActivity.class);
		SplashActivity.this.startActivity(intent);
		SplashActivity.this.finish();
	}

	private Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case GO_HOME:
				goHome();
				break;
			case GO_GUIDE:
				goGuide();
				break;
			}
			super.handleMessage(msg);
		}
	};

}
